<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('批量修改发货数量')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <input id="mid" name="mid" th:value="${mid}" type="hidden">
            <ul>
                <li>
                    <label>发货单号：</label>
                    <input readonly="true" id="sendcode" name="sendcode" th:value="${sendcode}" type="text">
                </li>
                <li>
                    <label>物流单号：</label>
                    <input id="logcode" name="logcode" type="text" required>
                </li>
                <li>
                    <label>是否厂家代发货：</label>
                   <!-- <input id="isreplace" name="isreplace" type="text" required>-->
                    <select id="isreplace"  name="isreplace" required>
                        <option value="否">否</option>
                        <option value="是">是</option>
                    </select>
                </li>
                <li>
                    <label>发货仓库：</label>
                    <select id="fromwh" name="fromwh" >
                        <option value=""></option>
                        <option th:each="item:${items}" th:value="${item.ffullnumber}" th:text="${item.fname}"></option>
                    </select>
                </li>
                <li>
                    <label>发货备注：</label>
                    <textarea id="smemo" name="smemo" type="text"></textarea>
                </li>
            </ul>


            <!--<div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>表头ID：</label>
                                <input type="text" name="mid"/>
                            </li>
                            <li>
                                <label>表头单号：</label>
                                <input type="text" name="mcode"/>
                            </li>
                            <li>
                                <label>产品代码：</label>
                                <input type="text" name="pcode"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="pname"/>
                            </li>
                            <li>
                                <label>产品规格：</label>
                                <input type="text" name="pstd"/>
                            </li>
                            <li>
                                <label>单位：</label>
                                <input type="text" name="punit"/>
                            </li>
                            <li>
                                <label>备注：</label>
                                <input type="text" name="smemo"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>-->

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:sos:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="erp:sos:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="erp:sos:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:sos:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:sos:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:sos:remove')}]];
        var prefix = ctx + "erp/sos";
        var mid = $("#mid").val();
        $(function() {
            var options = {
                url: prefix + "/list?mid="+mid,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                showPageGo: true,
                onEditableSave: onEditableSave,
                columns: [{
                    checkbox: false
                },
                {
                    field: 'mid', 
                    title: '表头ID',
                    visible: false
                },
                {
                    field: 'mcode', 
                    title: '表头单号'
                },
                    {
                        field: 'itemcode',
                        title: '金蝶编码'
                    },
                {
                    field: 'pcode', 
                    title: '产品代码'
                },
                {
                    field: 'pname', 
                    title: '产品名称'
                },
                {
                    field: 'pstd', 
                    title: '产品规格'
                },
                {
                    field: 'punit', 
                    title: '单位'
                },
                {
                    field: 'qty', 
                    title: '订单数量'
                },
                {
                    field: 'sendqty', 
                    title: '已发货数量'
                },
                    {
                        field: 'currentSendqty',
                        title: '本次发货数量',
                        editable: {
                            type: 'text',
                            title: '本次发货数量',
                            validate: function (v) {
                                debugger;
                                if (!v) return '本次发货数量不能为空';
                            }
                        },
                    },
                {
                    field: 'smemo', 
                    title: '备注'
                }]
            };
            $.table.init(options);
        });

        function onEditableSave (field, row, oldValue, $el) {
            debugger;
            if((parseInt(row[field]) + parseInt(row.sendqty)) > row.qty){
                $.modal.msgError("发货数量不能超过订货数量");
                $el.innerText(oldValue);
                return false;
            }

           // alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue);
        }

        /* 添加用户-选择用户-提交 */
        function submitHandler() {
            debugger;
            $.modal.disable();
            var logcode = $("#logcode").val();
            if(logcode == ""){
                $.modal.msgError("请填写物流号");
            }else{
                var data = $("#" + table.options.id).bootstrapTable('getData');
                $.ajax({
                    type: "post",
                    url: ctx + "erp/sos/batckUpdate?sendcode="+ $("#sendcode").val()+"&smemo="+$("#smemo").val()+"&logcode="+$("#logcode").val()+"&mid="+mid+"&isreplace="+$("#isreplace").val()+"&fromwh="+$("#fromwh").val()+"&fromwhname="+$("#fromwh").find("option:selected").text(),
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify(data),
                    dataType: "json",
                    success: function(r) {
                        $.modal.msgSuccess("修改成功");
                        $.modal.close();
                    }
                });
            }
        }
    </script>
</body>
</html>